﻿using System;
using System.Collections.ObjectModel;
using QueryBuilder.Controls.Configuration;
using QueryBuilder.Core.Visualization;
using QueryBuilder.Core.Visualization.Commands;
using QueryBuilder.Core.Visualization.QueryVisualization;

namespace QueryBuilder.Controls
{
    public class SqlConstraintVisualizerViewModel : ViewModel
    {
        private readonly ObservableCollection<VisualizableConstraint> visualizableConstraints = new ObservableCollection<VisualizableConstraint>();
        private ObservableCollection<string> comparisonCollection = new ObservableCollection<string>();
        private ComparisonTemplateConfiguration comparisonTemplateConfiguration;
        private VisualizationConfig visualizationConfig;
        public DelegateCommand<object> AddExpressionCommand { get; private set; }

        public SqlConstraintVisualizerViewModel()
        {
            this.DeleteExpressionCommand = new DelegateCommand<object>(this.OnDeleteExpressionCommand);
            this.AddExpressionCommand = new DelegateCommand<object>(this.OnAddExpressionCommand);
        }

        private void OnAddExpressionCommand(object value)
        {
            
        }

        public DelegateCommand<object> DeleteExpressionCommand { get; private set; }

        public ObservableCollection<VisualizableConstraint> VisualizableConstraints
        {
            get { return this.visualizableConstraints; }
        }

        public ComparisonTemplateConfiguration ComparisonTemplateConfiguration
        {
            get { return this.comparisonTemplateConfiguration; }
            set { this.SetValue(ref this.comparisonTemplateConfiguration, value, () => this.ComparisonTemplateConfiguration); }
        }

        public VisualizationConfig VisualizationConfig
        {
            get { return this.visualizationConfig; }
            set { this.SetValue(ref this.visualizationConfig, value, () => this.VisualizationConfig); }
        }

        public ObservableCollection<string> ComparisonCollection
        {
            get { return this.comparisonCollection; }
        }

        private void OnDeleteExpressionCommand(object value)
        {
            var visualizableConstriant = value as VisualizableConstraint;
            visualizableConstriant.Parent.RemoveChild(visualizableConstriant);
        }
    }
}